﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Reflection;
using System.Web.Mvc;



namespace com.IronOne.BoardAppWeb.Models.Paper
{
    public class PaperModel
    {
        public int PaperId { get; set; }

        [Required(ErrorMessage = "Please enter document name.")]
        public string DocName { get; set; }

        public byte DocType { get; set; } // 0 - Main, 1-SupportDoc

        public DocumentType DocTypeValue { get; set; }

        //public byte RefType { get; set; } // 0 - Paper, 1- Meeting

        public int? headingId { get; set; }

        public string Description { get; set; }

        public string PaperRefNo { get; set; }
        
        //public byte? PaperStatus { get; set; }
        public PaperStatus PaperStatusValue { get; set; }

        public PaperStatus PreviousPaperStatusValue { get; set; }

        public string StatusComment { get; set; }

        public int Order { get; set; }

        public int meetingId { get; set; }

        //public string CategoryName { get; set; }

        //public DateTime MeetingDate { get; set; }

        //public DateTime UploadedDate { get; set; }

        //public int UploadedBy { get; set; }

        public int CategoryID { get; set; }
        

        //public PaperStatus PaperStatusValue { get; set; }

        //public List<string> Keywords { get; set; }

        public string Keywords { get; set; }

        public int? AdditionalRefId { get; set; }

        public string FilePath { get; set; }

        public override string ToString()
        {
            return " " + this.PaperId + this.DocName + this.DocType + this.headingId 
                +this.Description +this.PaperRefNo  +this.StatusComment+ this.Order 
                +this.meetingId+this.CategoryID +this.Keywords+this.AdditionalRefId+this.FilePath+"";
        }
    }

    public class PaperListModel
    {
        public int PaperId { get; set; }
        public string PaperName { get; set; }
        public string Description { get; set; }
        public byte DocType { get; set; }
        public string PaperRefNo { get; set; }
        public int meetingId { get; set; }

        //public DateTime UploadedDate { get; set; }

        public string PaperStatus { get; set; }

        public override string ToString()
        {
            return " " + this.PaperId + this.PaperName + this.DocType + this.Description
                + this.DocType + this.PaperRefNo + this.PaperRefNo+"";
        }

    }

    public enum DocumentType 
    {
        [Description("Paper for Approval")]
        BoardPaper ,       
        [Description("Information Paper")]
        InformationPaper,
        [Description("Discussion Item")]
        DiscussionItem,
        [Description("Support Document")]
        SupportDocument
    }

    public enum PaperStatus 
    {
        [Description("Pending")]
        Pending ,
        [Description("Approved")]
        Approved,
        [Description("Rejected")]
        Rejected,
        [Description("Carried Forward")]
        CarriedForward,
        [Description("Cancelled")]
        Cancelled,
        [Description("Confirmed")]
        Confirmed,
        [Description("Withdrawn")]
        Withdrawn
    }
    public enum InfoOnlyPaperStatus 
    {
        [Description("Pending")]
        Pending ,
        [Description("Carried Forward")]
        CarriedForward,
        [Description("Cancelled")]
        Cancelled,
        [Description("Confirmed")]
        Confirmed,
        [Description("Withdrawn")]
        Withdrawn        
    }

    public class HeadingModel
    {
        public int HeadingId { get; set; }
        public int? PreviousHeadingId { get; set; }
        public string Description { get; set; }
        public int MeetingId { get; set; }
        public int AgendaOrder { get; set; }
        public override string ToString()
        {
            return " " + this.HeadingId +" "+ this.PreviousHeadingId+" " + this.Description+" " + this.MeetingId+" "
                + this.AgendaOrder + "";
        }
    }

    public class CommentModel
    {
        public int CommentId { get; set; }
        public int? RefId { get; set; }
        public int RefType { get; set; }
        public string Comment { get; set; }
        public DateTime CreatedDate { get; set; }
        public string CommentedBy { get; set; }
        public override string ToString()
        {
            return " " + this.CommentId + " " + this.RefId + " " + this.RefType + " " + this.Comment + " "
                + this.CreatedDate + " " + this.CommentedBy + "";
        }
    }

    public class ApprovalsModel
    {
        public string Name { get; set; }
        public byte DecisionStatus { get; set; }
        public string Papername { get; set; }

        public override string ToString()
        {
            return " " + this.Name + " " + this.DecisionStatus + " " + this.Papername + "";
        }
    }

    public class PastPaperSearchModel
    {
        public DateTime? MeetingDateFrom { get; set; }

        public DateTime? MeetingDateTo { get; set; }

        public int? PaperStatus { get; set; }

        public string PaperRefNo { get; set; }

        public string KeyWord { get; set; }

        public override string ToString()
        {
            return " " + this.MeetingDateFrom + " " + this.MeetingDateTo + " " + this.PaperStatus + " "+this.PaperRefNo+" "+this.KeyWord;
        }
    }

    public class PastPaperModel
    {
        public DateTime? MeetingDate { get; set; }

        public string DocName { get; set; }

        public string Description { get; set; }       

        public string MeetingSubCategory { get; set; }

        public string PaperRefNo { get; set; }
        
        public int paperStatus { get; set; }

        public string PaperStatusValue { get; set; }

        public int paperId { get; set; }

        public byte DocType { get; set; }

        public int MeetingId { get; set; }

        public int VersionID { get; set; }

        public string MeetingStatusValue { get; set; }

        public int MeetingType { get; set; }

        public override string ToString()
        {
            return " " + this.MeetingDate + " " + this.DocName + " " + this.Description + " " + this.MeetingSubCategory + " " + this.PaperRefNo + " " + this.paperStatus + " " + this.PaperStatusValue + " " + this.paperId + " " + this.DocType + " " + MeetingId + " " + this.VersionID + " " + this.MeetingStatusValue;
        }
    }


   public static class DropdownListGenrator
    {
        
        public static IEnumerable<T> EnumToList<T>()
        {
            Type enumType = typeof(T);


            if (enumType.BaseType != typeof(Enum))
                throw new ArgumentException("T must be of type System.Enum");

            Array enumValArray = Enum.GetValues(enumType);
            List<T> enumValList = new List<T>(enumValArray.Length);

            foreach (int val in enumValArray)
            {
                enumValList.Add((T)Enum.Parse(enumType, val.ToString()));
            }

            return enumValList;
        }


        public static string GetEnumDescription(Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes =
                (DescriptionAttribute[])fi.GetCustomAttributes(
                typeof(DescriptionAttribute),
                false);

            if (attributes != null &&
                attributes.Length > 0)
                return attributes[0].Description;
            else
                return value.ToString();
        }


        public static IEnumerable<SelectListItem> GetdropDownList()
        {
            List<SelectListItem> dropdownList = new List<SelectListItem>();
            int enumerationValue = 0;

            foreach (DocumentType state in EnumToList<DocumentType>())
            {
                dropdownList.Add(new SelectListItem
                {
                    Text = GetEnumDescription(state),
                    Value =enumerationValue.ToString(),
                    
                });
                enumerationValue++;
            }
            return dropdownList;
        }


        public static IEnumerable<SelectListItem> GetdropDownList(string doctype)
        {
            List<SelectListItem> dropdownList = new List<SelectListItem>();
            int enumerationValueSelected = 0;
            int enumerationValueNotselected = 0;
            
            //first put the selected value to dropdownlist
            foreach (DocumentType state in EnumToList<DocumentType>())
            {
                         
                Boolean selectedval = ((state.ToString()).Equals(doctype))?true:false;

                if (selectedval)
                {
                    dropdownList.Add(new SelectListItem
                    {
                        Text = GetEnumDescription(state),
                        Value = enumerationValueSelected.ToString(),
                        
                    });
                }
                enumerationValueSelected++;
            }

            //then put the unsilected values dropdownlist
            foreach (DocumentType state in EnumToList<DocumentType>())
            {

                Boolean selectedval = ((state.ToString()).Equals(doctype)) ? true : false;

                if (!selectedval)
                {
                    dropdownList.Add(new SelectListItem
                    {
                        Text = GetEnumDescription(state),
                        Value = enumerationValueNotselected.ToString(),
                       
                    });
                }
                enumerationValueNotselected++;
            }


            return dropdownList;
        }


        //dropdown list for paperstatus
        public static IEnumerable<SelectListItem> GetdropDownListPaperStatus(string paperstatus)
        {
            List<SelectListItem> dropdownList = new List<SelectListItem>();
            int enumerationValueSelected = 0;
            int enumerationValueNotselected = 0;

            //first put the selected value to dropdownlist
            foreach (PaperStatus state in EnumToList<PaperStatus>())
            {

                Boolean selectedval = ((state.ToString()).Equals(paperstatus)) ? true : false;

                if (selectedval)
                {
                    dropdownList.Add(new SelectListItem
                    {
                        Text = GetEnumDescription(state),
                        Value = enumerationValueSelected.ToString(),

                    });
                }
                enumerationValueSelected++;
            }

            //then put the unsilected values dropdownlist
            foreach (PaperStatus state in EnumToList<PaperStatus>())
            {

                Boolean selectedval = ((state.ToString()).Equals(paperstatus)) ? true : false;

                if (!selectedval)
                {
                    dropdownList.Add(new SelectListItem
                    {
                        Text = GetEnumDescription(state),
                        Value = enumerationValueNotselected.ToString(),

                    });
                }
                enumerationValueNotselected++;
            }


            return dropdownList;
        }


        //dropdown list for paperstatus
        public static IEnumerable<SelectListItem> GetdropDownListInfoOnlyPaperStatus(string infopaper)
        {
            List<SelectListItem> dropdownList = new List<SelectListItem>();


            int enumerationValueSelected = 0;
            int enumerationValueNotselected = 0;

            //first put the selected value to dropdownlist
            foreach (InfoOnlyPaperStatus state in EnumToList<InfoOnlyPaperStatus>())
            {

                Boolean selectedval = ((state.ToString()).Equals(infopaper)) ? true : false;

                if (selectedval)
                {
                    dropdownList.Add(new SelectListItem
                    {
                        Text = GetEnumDescription(state),
                        Value = enumerationValueSelected.ToString(),

                    });
                }
                enumerationValueSelected = (enumerationValueSelected == 0) ? 3 : ++enumerationValueSelected;
            }

            //then put the unselected values dropdownlist
            foreach (InfoOnlyPaperStatus state in EnumToList<InfoOnlyPaperStatus>())
            {

                Boolean selectedval = ((state.ToString()).Equals(infopaper)) ? true : false;

                if (!selectedval)
                {
                    dropdownList.Add(new SelectListItem
                    {
                        Text = GetEnumDescription(state),
                        Value = enumerationValueNotselected.ToString(),

                    });
                }
                enumerationValueNotselected = (enumerationValueNotselected == 0) ? 3 : ++enumerationValueNotselected;
            }


            return dropdownList;
        }


    }


    

}